package com.ruoyi.attached.service.impl;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.sample.domain.Sample;
import com.ruoyi.sample.mapper.SampleMapper;
import com.ruoyi.sample.service.ISampleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.attached.mapper.AttachedMapper;
import com.ruoyi.attached.domain.Attached;
import com.ruoyi.attached.service.IAttachedService;

/**
 * 附Service业务层处理
 *
 * @author ruoyi
 * @date 2025-05-08
 */
@Service
public class AttachedServiceImpl implements IAttachedService
{
    @Autowired
    private AttachedMapper attachedMapper;

    @Autowired
    private SampleMapper sampleMapper;


    /**
     * 查询附
     *
     * @param id 附主键
     * @return 附
     */
    @Override
    public Attached selectAttachedById(Long id)
    {
        return attachedMapper.selectAttachedById(id);
    }

    public Map<String, Object> getInfoAll(String ids,String businessType){
        HashMap<String, Object> map = new HashMap<>();


        String[] idsArr = ids.split(",");
        Long[] longArray = new Long[idsArr.length];

        for (int i = 0; i < idsArr.length; i++) {
            longArray[i] = Long.parseLong(idsArr[i]);
        }

        //所有附表
        List<Attached> attachedList = attachedMapper.selectAttachedByIds(longArray);
        map.put("businessType",businessType);
        map.put("attachedList",attachedList);

//        Long[] attachedArray = new Long[attachedList.size()];
//        int i = 0;
//        for (Attached attached : attachedList) {
//            attachedArray[i] = attached.getId();
//            i++;
//        }

        if("shinei".equals(businessType)){
            List<Sample> sampleList = sampleMapper.selectSampleByAttachedIds(longArray);
            map.put("sampleList",sampleList);
        }

        if("shiwai".equals(businessType)){

        }


        return map;
    }

    /**
     * 查询附列表
     *
     * @param attached 附
     * @return 附
     */
    @Override
    public List<Attached> selectAttachedList(Attached attached)
    {
        return attachedMapper.selectAttachedList(attached);
    }

    /**
     * 新增附
     *
     * @param attached 附
     * @return 结果
     */
    @Override
    public int insertAttached(Attached attached)
    {
        attached.setCreateTime(DateUtils.getNowDate());
        return attachedMapper.insertAttached(attached);
    }

    /**
     * 修改附
     *
     * @param attached 附
     * @return 结果
     */
    @Override
    public int updateAttached(Attached attached)
    {
        attached.setUpdateTime(DateUtils.getNowDate());
        return attachedMapper.updateAttached(attached);
    }

    /**
     * 批量删除附
     *
     * @param ids 需要删除的附主键
     * @return 结果
     */
    @Override
    public int deleteAttachedByIds(Long[] ids)
    {
        return attachedMapper.deleteAttachedByIds(ids);
    }


    /**
     * 批量逻辑删除附
     *
     * @param ids 需要删除的附主键
     * @return 结果
     */
    @Override
    public int logicDeleteAttached(Long[] ids,String delType,Long delUser)
    {


        return attachedMapper.logicDeleteAttached(ids,delType,delUser);
    }

    /**
     * 删除附信息
     *
     * @param id 附主键
     * @return 结果
     */
    @Override
    public int deleteAttachedById(Long id)
    {
        return attachedMapper.deleteAttachedById(id);
    }
}
